// NationscapeEconomics
log using NationscapeEconomics.log, replace
use "C:\Users\sbstjp\OneDrive - Cardiff University\Nationscapedataset.dta" // Tausanovitch, Chris and Lynn Vavreck. 2020. Democracy Fund + UCLA Nationscape, October 10-17, 2019 (version 20200814). Retrieved from [URL].  Date accessed: March 09, 2025.

keep statements_gender_identity reparations group_favorability_blm group_favorability_undocumented weight economy_better employment household_income extra_housing extra_income_corona extra_worry_finances extra_savings extra_prepare_money extra_lost_job extra_spouse_lost_job extra_mortgage_difficulty extra_stud_loan_difficulty extra_car_pay_difficulty extra_drop_income extra_satisf_job extra_satisf_income extra_satisf_savings extra_satisf_debt start_date

// Social justice scale
*Drop missing values
replace statements_gender_identity=. if statements_gender_identity>4 
replace group_favorability_blm=. if group_favorability_blm>4 
replace reparations=. if reparations>2 
replace group_favorability_undocumented=. if group_favorability_undocumented==999 

*Rename so shorter
rename group_favorability_blm blm
rename group_favorability_undocumented undocumented
rename statements_gender_identity genderidentity

*Reverse variables so social justice is coded high
foreach var in blm reparations undocumented {
    qui sum `var'
    local max_value = r(max)
    gen r`var' = `max_value' + 1 - `var'
}

*Standardize items in the scale from 1-2 - this avoids 0, for reasons outlined in next step
foreach var in rblm rreparations rundocumented genderidentity {
    summarize `var'
    gen s`var' = 1 + (`var' - r(min)) / (r(max) - r(min))
}

* Replace missing values with 0 for the specified variables - this is necessary as Stata doesn't add up missing values
foreach var in srblm srreparations srundocumented sgenderidentity {
    replace `var' = 0 if missing(`var')
}

* Initialize the total score and the count of non-zero responses
gen total_scoreSJV = 0
gen count_nonzeroSJV = 0

* Add each variable to the total scale score and count it if non-zero
foreach var in srblm srreparations srundocumented sgenderidentity {
    replace total_scoreSJV = total_scoreSJV + `var'
    replace count_nonzeroSJV = count_nonzeroSJV + (`var' != 0)
}

* Calculate the average score, avoiding division by zero
gen SocJusValues = .
replace SocJusValues = total_scoreSJV / count_nonzeroSJV if count_nonzeroSJV > 0

// Economics
*Create dummies
gen unemployed=.
replace unemployed=1 if employment==4
replace unemployed=0 if inlist(employment, 1, 5, 8)

gen housingtenant=.
replace housingtenant=1 if extra_housing==1
replace housingtenant=0 if inrange(extra_housing, 2, 4)

*Delete missing values
replace extra_lost_job=. if extra_lost_job==999
replace extra_spouse_lost_job=. if extra_spouse_lost_job==999
replace extra_mortgage_difficulty=. if extra_mortgage_difficulty==999
replace extra_stud_loan_difficulty=. if extra_stud_loan_difficulty==999
replace extra_car_pay_difficulty=. if extra_car_pay_difficulty==999
replace extra_drop_income=. if extra_drop_income==999
replace extra_worry_finances=. if extra_worry_finances==999

*Reverse variables so difficult/precarious economic conditions are coded low
foreach var in economy_better unemployed housingtenant extra_income_corona extra_savings extra_prepare_money extra_satisf_job extra_satisf_income extra_satisf_savings extra_satisf_debt {
    qui sum `var'
    local max_value = r(max)
    gen r`var' = `max_value' + 1 - `var'
}

// Correlations
pwcorr SocJusValues reconomy_better runemployed household_income rhousingtenant rextra_income_corona extra_worry_finances rextra_savings rextra_prepare_money extra_lost_job extra_spouse_lost_job extra_mortgage_difficulty extra_stud_loan_difficulty extra_car_pay_difficulty extra_drop_income rextra_satisf_job rextra_satisf_income rextra_satisf_savings rextra_satisf_debt [aweight=weight], sig 

pwcorr SocJusValues reconomy_better runemployed household_income rhousingtenant rextra_income_corona extra_worry_finances rextra_savings rextra_prepare_money extra_lost_job extra_spouse_lost_job extra_mortgage_difficulty extra_stud_loan_difficulty extra_car_pay_difficulty extra_drop_income rextra_satisf_job rextra_satisf_income rextra_satisf_savings rextra_satisf_debt if quarter(dofc(start_date)) == 4 & year(dofc(start_date)) == 2020 [aweight=weight], sig 

log close


